#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

i64 dp[401][401][401][2];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, L;
  cin >> n >> L;
  vector<int> p(n), t(n);
  for (int i = 0; i < n; i ++) cin >> p[i];
  for (int i = 0; i < n; i ++) cin >> t[i];
  p.push_back(L);
  t.push_back(-1);
  for (int i = 0; i < n; i ++) {
    p.push_back(p[i] + L);
    t.push_back(t[i]);
  }
  const i64 inf = LLONG_MAX / 2;
  for (int l = 2 * n; l >= 0; l --) {
    dp[l][l][0][0] = dp[l][l][0][1] = (l == n ? 0 : inf);
    for (int c = 1; c <= n; c ++) dp[l][l][c][0] = dp[l][l][c][1] = inf;
    for (int r = l + 1; r <= 2 * n; r ++) {
      for (int c = 0; c <= n; c ++) {
        dp[l][r][c][0] = inf;
        if (dp[l+1][r][c][0] + abs(p[l+1] - p[l]) > t[l]) {
          dp[l][r][c][0] = min(dp[l][r][c][0], dp[l+1][r][c][0] + abs(p[l+1] - p[l]));
        }
        if (c && dp[l+1][r][c-1][0] + abs(p[l+1] - p[l]) <= t[l]) {
          dp[l][r][c][0] = min(dp[l][r][c][0], dp[l+1][r][c-1][0] + abs(p[l+1] - p[l]));
        }
        if (dp[l+1][r][c][1] + abs(p[r] - p[l]) > t[l]) {
          dp[l][r][c][0] = min(dp[l][r][c][0], dp[l+1][r][c][1] + abs(p[r] - p[l]));
        }
        if (c && dp[l+1][r][c-1][1] + abs(p[r] - p[l]) <= t[l]) {
          dp[l][r][c][0] = min(dp[l][r][c][0], dp[l+1][r][c-1][1] + abs(p[r] - p[l]));
        }
        dp[l][r][c][1] = inf;
        if (dp[l][r-1][c][0] + abs(p[r] - p[l]) > t[r]) {
          dp[l][r][c][1] = min(dp[l][r][c][1], dp[l][r-1][c][0] + abs(p[r] - p[l]));
        }
        if (c && dp[l][r-1][c-1][0] + abs(p[r] - p[l]) <= t[r]) {
          dp[l][r][c][1] = min(dp[l][r][c][1], dp[l][r-1][c-1][0] + abs(p[r] - p[l]));
        }
        if (dp[l][r-1][c][1] + abs(p[r] - p[r-1]) > t[r]) {
          dp[l][r][c][1] = min(dp[l][r][c][1], dp[l][r-1][c][1] + abs(p[r] - p[r-1]));
        }
        if (c && dp[l][r-1][c-1][1] + abs(p[r] - p[r-1]) <= t[r]) {
          dp[l][r][c][1] = min(dp[l][r][c][1], dp[l][r-1][c-1][1] + abs(p[r] - p[r-1]));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i ++) {
    for (int c = ans + 1; c <= n; c ++) {
      if (dp[i][i+n][c][0] != inf || dp[i][i+n][c][1] != inf) {
        ans = max(ans, c);
      }
    }
  }
  cout << ans << endl;
}